package com.txunda.zhuohired.aty.user.news;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.ants.theantsgo.gson.GsonUtil;
import com.ants.theantsgo.util.L;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.adapter.user.news.SystemInformAdapter;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.bean.user.my.SystemInfoBean;
import com.txunda.zhuohired.http.pst.MessagePst;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/6 10:45
 * 功能描述：系统通知
 * 联系方式：jiahuanchen@126.com
 */

public class SystemInformAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * listView
     */
    @ViewInject(R.id.lv_system_inform)
    private ListView lv_system_inform;
    private List<SystemInfoBean.DataBean> systemList;

    private SystemInformAdapter systemInformAdapter;
    private MessagePst messagePst;
    private int page =1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("系统通知");
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_system_inform;
    }

    @Override
    protected void initialized() {
        messagePst = new MessagePst(this);
        systemList  = new ArrayList<>();
    }

    @Override
    protected void requestData() {
        messagePst.sysMsg(String.valueOf(page));
//        initAdapter();
    }

    private void initAdapter() {
        systemInformAdapter = new SystemInformAdapter(this,systemList);
        lv_system_inform.setAdapter(systemInformAdapter);
        lv_system_inform.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                showRightTip("被点击了");
                Bundle bundle = new Bundle();
                bundle.putString("id",systemList.get(i).getSys_msg_id());
                startActivity(SystemNewsDetailsAty.class, bundle);
            }
        });
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if(requestUrl.contains("sysMsg")){
            L.e("=====sysMsg=======",jsonStr);
            SystemInfoBean systemInfoBean = GsonUtil.GsonToBean(jsonStr,SystemInfoBean.class);

            systemList = systemInfoBean.getData();

            initAdapter();
        }
    }
}
